﻿/**********************************************************
*
* 模块名称：示例类1(通用数据操作)
* 当前版本：1.0
* 添加人员：楚涛
* 开始时间：2010-10-10
* 版本历史：v1.0
*
***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Database;
using LXChuTao.ECG.Demo.Entity;
using LXChuTao.ECG.Demo.BLL.SimpleFactory;

namespace LXChuTao.ECG.Demo.BLL
{
    public class Container1 : BaseContainer
    {
        public static DataSet GetDataSet()
        {
            DbCore dbCore = GetDbCore;
            return dbCore.Select().Add(T_DEMO.s_C_ID).Add(T_DEMO.s_C_NAME).Add(T_DEMO.s_C_DATE)
                .From(T_DEMO.s_TableName).Where().ConditionAndLessEqual(T_DEMO.s_C_EIDTDATE, DateTime.Now)
                .ExecuteDataSet();
        }
        public static int Insert()
        {
            DbCore dbCore = null;
            try
            {
                dbCore = GetDbCore;
                dbCore.Open();
                int count = dbCore.InsertInto(T_DEMO.s_TableName).Values(T_DEMO.s_C_ID,GetKeyId)
                    .Values(T_DEMO.s_C_NAME, "NameInsert").Values(T_DEMO.s_C_IDCARD, "340221196606066066")
                    .Values(T_DEMO.s_C_DATE, DateTime.Today).Values(T_DEMO.s_C_INT,10)
                    .Values(T_DEMO.s_C_FLOAT,11.11).Values(T_DEMO.s_C_EIDTDATE, DateTime.Now)
                    .ExecuteNonQuery();
                dbCore.Close();
                return count;
            }
            catch (Exception ex)
            {
                if (dbCore != null) dbCore.Close();
                throw ex;
            }

        }
        public static int Update()
        {
            DbCore dbCore = null;
            try
            {
                dbCore = GetDbCore;
                dbCore.Open();
                int count = dbCore.UpdateFrom(T_DEMO.s_TableName).Set(T_DEMO.s_C_NAME,"NameSet")
                    .Set(T_DEMO.s_C_EIDTDATE,DateTime.Now).Set(T_DEMO.s_C_DATE,DateTime.Today)
                    .Where().ConditionAndEqual(T_DEMO.s_C_ID,"0123456789")
                    .ExecuteNonQuery();
                dbCore.Close();
                return count;
            }
            catch (Exception ex)
            {
                if (dbCore != null) dbCore.Close();
                throw ex;
            }

        }
        public static int Delete()
        {
            DbCore dbCore = null;
            try
            {
                dbCore = GetDbCore;
                dbCore.Open();
                int count = dbCore.DeleteFrom(T_DEMO.s_TableName)
                    .Where().ConditionAndGreatEqual(T_DEMO.s_C_EIDTDATE, DateTime.Now)
                    .ExecuteNonQuery();
                dbCore.Close();
                return count;
            }
            catch (Exception ex)
            {
                if (dbCore != null) dbCore.Close();
                throw ex;
            }

        }

        public static string TestFactory()
        {
            string str = TestSimpleFactory.Test();
            return str;
        }
    }
}
